package org.geektimes.configuration.microprofile.config.source;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Map;
import java.util.Properties;

public class DefaultLocalPropertiesConfigSource extends MapBaseConfigSource {

    private static final String MICROPROFILE_CONFIG_FILE_URL = "META-INF/config.properties";

    public DefaultLocalPropertiesConfigSource() {
        super("Default Local Properties Config Source", 300);
    }

    @Override
    protected void parseConfigData(Map configData) {
         URL resource = this.getClass().getClassLoader().getResource(MICROPROFILE_CONFIG_FILE_URL);
            if (resource == null) {
                logger.info("The default config file[META-INF/config.properties] can be not found");
                return;
            }

            try {
                InputStream inputStream = resource.openStream();
                Properties properties = new Properties();
                properties.load(inputStream);
                configData.putAll(properties);
            } catch (IOException e) {
                e.printStackTrace();
            }


    }
}
